package com.xiaohu.myspace.buiness.buinessinterfaceimple;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.xiaohu.myspace.buiness.BaseBuiness;
import com.xiaohu.myspace.buiness.buinessinterface.UserInfoInterface;
import com.xiaohu.myspace.database.dao.UserInfoDao;
import com.xiaohu.myspace.database.entity.UserInfo;

public class UserInfoInterfaceImple extends BaseBuiness implements
		UserInfoInterface {

	private UserInfoDao userInfoDao;

	public UserInfoDao getUserInfoDao() {
		return userInfoDao;
	}

	public void setUserInfoDao(UserInfoDao userInfoDao) {
		this.userInfoDao = userInfoDao;
	}

	@Override
	public boolean insertUserInfo(final UserInfo userInfo) {

		return doSomeThingInDB(new DoInBuiness<Boolean>() {

			@Override
			public Boolean doSomeThingInBuiness(SessionFactory sessionFactory,
					Session session) {
				return userInfoDao.insertUserInfo(userInfo, session);
			}
		});
	}

	@Override
	public UserInfo loginWithUserInfo(final UserInfo userInfo) {
		return doSomeThingInDB(new DoInBuiness<UserInfo>() {

			@Override
			public UserInfo doSomeThingInBuiness(SessionFactory sessionFactory,
					Session session) {
				return  userInfoDao.loginWithUserInfo(userInfo, session);
			}
		});
		
	}

	@Override
	public boolean userNameExist(String userName) {

		return doSomeThingInDB(new DoInBuiness<Boolean>() {

			@Override
			public Boolean doSomeThingInBuiness(SessionFactory sessionFactory,
					Session session) {
				return false;
			}
			
		});
	}

}
